/*
 * TesteEMATHEMA.java
 *
 * Created on 27 de Setembro de 2006, 02:30
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.ufal.ic.forbile.infra;

import br.ufal.ic.forbile.infra.GenericKAO;
import br.ufal.ic.forbile.infra.emathema.ontology.Credential;
import br.ufal.ic.forbile.infra.emathema.ontology.Curriculum;
import br.ufal.ic.forbile.infra.emathema.ontology.EMATHEMAFactory;
import br.ufal.ic.forbile.infra.emathema.ontology.PartitionDomain;
import edu.stanford.smi.protegex.owl.model.OWLIndividual;
import edu.stanford.smi.protegex.owl.model.RDFResource;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Ig Ibert
 */
public class TesteEMATHEMA {
    
    /** Creates a new instance of TesteEMATHEMA */
    public TesteEMATHEMA() {
    }
    
    public static void main(String [] args) throws Exception{
        
//        GenericKAO instance = new GenericKAO();
//
//        Class cls = Class.forName("br.ufal.ic.forbile.infra.emathema.ontology.Curriculum");
//
//        OWLIndividual ic = instance.retrieve("Curriculum_Artigo121", "curriculum");
//
//        cls.cast(ic);
        create();
    }
    
    public static void create() throws Exception {
        Map<String, Object> configuration = new HashMap();
        GenericKAO instance = new GenericKAO("emathema");
        
        configuration.put("Name", PartitionDomain.class);
        configuration.put("Individual", "PartitionDomain_ateasstea");
        configuration.put("Description", "asdkhcbas");
        configuration.put("Issue", "asdhbc");
        
        //ExternalView ic = (ExternalView) instance.retrieve("ExternalView_Direito", "ExternalView");
        
        configuration.put("has_domain", "ExternalView_Direito");
        
        instance.create(configuration);
//        EMATHEMAKnowledge em = EMATHEMAKnowledge.getInstance("EMATHEMAOWL.pprj");
//        PartitionDomain cred = em.getEmathema().createCredential("testesemagente");
        
        //cred.setHas_domain()
        
//        Collection c = new ArrayList<String>();
//        c.add("logintesteCollection");
//
//        cred.setLogin(c);
//        cred.setPassword(c);
//        em.save();
    }
    
    public static void delete() throws Exception {
        Map<String, Object> configuration = new HashMap();
        configuration.put("Name", Credential.class);
        
        configuration.put("Individual", "Qualquer3");
        
        GenericKAO instance = new GenericKAO("emathema");
        
        instance.delete(configuration);
    }
    
    public static void update() throws Exception {
        Map<String, Object> configuration = new HashMap();
        configuration.put("Name", Credential.class);
        
        configuration.put("Individual", "Qualquer4");
        configuration.put("Login", "Login");
        configuration.put("password", "password");
        
        GenericKAO instance = new GenericKAO("emathema");
        
        instance.update(configuration);
    }
    
    public static void retrieve() throws Exception{                                       
        GenericKAO instance = new GenericKAO("emathema");
        Curriculum ic = (Curriculum) instance.retrieve("Curriculum_Artigo121", "curriculum");
        System.out.println(ic);
        
        Map m = new HashMap();
        m = instance.retrieve(null, "rdf:type", ":Curriculum" );
        for ( Object o : m.keySet() ) {
            //System.out.println("ob "+o + "--"+ m.get(o));
            
            //owli
            OWLIndividual owli = (OWLIndividual)m.get(o);
            Curriculum cur = null;
            
            RDFResource res = owli.as(Curriculum.class);
            cur = (Curriculum)res;
            //System.out.println("curriculum "+ cur.getIsComposedBy_Depth().getIssue());
            System.out.println(cur.getName());
        }
        
    }
}
